package main

import (
	"fmt"
	"strings"
)

type Stack struct {
	ValList []string
}

func (s *Stack) Push(b string) {
	s.ValList = append(s.ValList, b)
}

func (s *Stack) Pop() string {
	if s.IsNull() {
		return ""
	}
	b := s.ValList[len(s.ValList)-1]
	s.ValList = s.ValList[:len(s.ValList)-1]
	return b
}

func (s *Stack) IsNull() bool {
	return len(s.ValList) == 0
}

func simplifyPath(path string) string {
	pathList := strings.Split(path, "/")
	stack := Stack{}
	for _, pathPart := range pathList {
		if pathPart == "" || pathPart == "." {
			continue
		} else if pathPart == ".." {
			stack.Pop()
		} else {
			stack.Push(pathPart)
		}
	}
	return "/" + strings.Join(stack.ValList, "/")
}

func main() {
	fmt.Println(simplifyPath("/a/./b/../../c/"))
}
